<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>DStation后台管理</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- Bootstrap Core CSS -->
    <link th:href="@{/boostrapTemplatResources/vendor/bootstrap/css/bootstrap.min.css}" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link th:href="@{/boostrapTemplatResources/vendor/metisMenu/metisMenu.min.css}" rel="stylesheet">

    <!-- Custom CSS -->
    <link th:href="@{/boostrapTemplatResources/dist/css/sb-admin-2.css}" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link th:href="@{/boostrapTemplatResources/vendor/morrisjs/morris.css}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link th:href="@{/boostrapTemplatResources/vendor/font-awesome/css/font-awesome.min.css}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="/webjars/jquery/3.1.1/jquery.js"></script>
    <script src="/js/sweetAlert.js"></script>
</head>

<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
    <div th:include="admin/header::header"></div>
    <div th:include="admin/sidebar::sidebar"></div>
</nav>

<!--显示主体部分 -->
<div id="wrapper">
    <!-- 主界面显示D站介绍信息 -->
    <div id="page-wrapper">
        <!-- 存放视频的分类信息的table -->
        <br>
        <table id="table"  class="table table-bordered">
            <thead>
            <tr>
                <th>视频编号</th>
                <th hidden>用户编号</th>
                <th>上传者</th>
                <th>视频标题</th>
                <th>状态</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="videoInfo : ${videoInfoIPage.records}">
                <td th:text="${videoInfo.videoId}"></td>
                <td th:text="${videoInfo.userId}" hidden></td>
                <td th:text="${videoInfo.userName}"></td>
                <td th:text="${videoInfo.videoTitle}"></td>
                <td th:if="${videoInfo.isPass} eq false">
                    <span class="label label-default">审核中</span>
                </td>
                <td th:text="${videoInfo.createDate}">
                </td>
                <td>
                    <a class="btn btn-sm btn-primary" th:onclick="displayVideoById([[${videoInfo.videoId}]],[[${videoInfo.videoURL}]])">查看视频</a>
                    <!--<a class="btn btn-info btn-xs" th:onclick="displayVideoById([[${videoInfo.videoId}]],[[${videoInfo.videoURL}]])">查看视频</a>-->
                    <a class="btn btn-sm btn-success" th:onclick="'intelligenceExamine('+${videoInfo.videoId}+')'">智能审核</a>
                    <a class="btn btn-sm btn-success" th:onclick="'access('+${videoInfo.videoId}+')'">通过</a>
                    <a class="btn btn-sm btn-danger" th:onclick="'reject('+${videoInfo.videoId}+')'">拒绝</a>
                </td>
            </tr>
            </tbody>
        </table>
        <div >
            <div class="center " style="padding-left: 45%;!important;">
                <a th:href="@{/videoExamine/videoExaminePage(page=${videoInfoIPage.current}-1)}"
                   th:class="${videoInfoIPage.current == 1}? 'disabled btn btn-primary btn-xs':'btn btn-primary btn-xs'"
                   class="btn btn-primary btn-xs" >上一页</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;
                <a th:href="@{/videoExamine/videoExaminePage(page=${videoInfoIPage.current}+1)}"
                   th:class="${videoInfoIPage.current == videoInfoIPage.pages?'disabled btn btn-primary btn-xs':'btn btn-primary btn-xs'}" class="btn btn-primary btn-xs">下一页</a>
            </div>
        </div>
        <div>
            <div class="center " style="padding-left: 45%;!important;">
                当前第 [[${videoInfoIPage.current}]]页,共 [[${videoInfoIPage.pages}]] 页.一共 [[${videoInfoIPage.total}]] 条记录
            </div>
        </div>
    </div>
    <!-- /#page-wrapper -->
</div>


<!-- 查看视频的模态框 -->
<div class="modal fade" id="videoModel" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" style="text-align:center;vertical-align:middle;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">查看视频</h4>
            </div>
            <div class="modal-body" style="text-align:center;vertical-align:middle;">
                <form class="form-horizontal" role="form"  style="text-align:center;vertical-align:middle;">
                    <div class="form-group" style="text-align:center;vertical-align:middle;">
                        <div  class="col-sm-10" style="text-align:center;vertical-align:middle;padding-left: 15%;">    <!-- -->
                            <video style="width: 100%; height: 100%;text-align:center;vertical-align:middle;" id="video" controls>

                            </video>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/boostrapTemplatResources/js/html5shiv.js}"></script>
<script th:src="@{/boostrapTemplatResources/js/respond.min.js}"></script>

<!-- jQuery -->
<script th:src="@{/boostrapTemplatResources/vendor/jquery/jquery.min.js}"></script>

<!-- Bootstrap Core JavaScript -->
<script th:src="@{/boostrapTemplatResources/vendor/bootstrap/js/bootstrap.min.js}"></script>

<!-- Metis Menu Plugin JavaScript -->
<script th:src="@{/boostrapTemplatResources/vendor/metisMenu/metisMenu.min.js}"></script>

<!-- Morris Charts JavaScript -->
<script th:src="@{/boostrapTemplatResources/vendor/raphael/raphael.min.js}"></script>
<script th:src="@{/boostrapTemplatResources/vendor/morrisjs/morris.min.js}"></script>
<script th:src="@{/boostrapTemplatResources/data/morris-data.js}"></script>

<!-- Custom Theme JavaScript -->
<script th:src="@{/boostrapTemplatResources/dist/js/sb-admin-2.js}"></script>

<script type="text/javascript">

    var intervalFlag = null;

    function displayVideoById(id, videoURL) {
        $("#video")[0].src = "/video/getVideoByVideoURL?videoURL=" + videoURL;
        $("#video")[0].poster = "/video/getVideoCoverageImgById?videoId=" + id;
        $("#videoModel").modal('show');
    }

    $('#videoModel').on('hidden.bs.modal', function () {
        // 执行一些动作...
        $("#video")[0].src = "";
        $("#video")[0].poster = "";
    })

    /**
     * 通过
     * @param id
     */
    function access(id) {
        swal({
            title: "确认弹框",
            text: "确定要通过吗?",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((flag) => {
            if(flag) {
                $.ajax(
                    {
                        type: "POST",
                        url: "/videoExamine/accessExamine",
                        async: false,
                        cache: true,
                        data: {
                            "id": id,
                            "isPass":1
                        },
                        success: function (data) {
                            if(data["res"] == true) {
                                swal("审核已通过!", {
                                    buttons: false,
                                    timer: 1000
                                });
                                window.location.reload();
                            } else {
                                swal("Error", "审核通过失败", "error");
                            }
                        },
                        error: function (data) {
                            swal("Error", "网络错误，请联系管理员！", "error");
                        }
                    }
                );
            }
        } );
    }


    /**
     * 智能审核
     * @param id
     */
    function intelligenceExamine(id) {
        if(intervalFlag != null) {
            swal("Warning", "有任务正在处理！", "warning");
            return ;
        }
        swal({
            title: "确认弹框",
            text: "已提交至智能审核，请及时查看结果！",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((flag) => {
            $.ajax(
                {
                    type: "POST",
                    url: "/videoExamine/intelligenceExamine",
                    async: false,    //设置为同步请求
                    cache: true,
                    data: {
                        "videoId": id
                    },
                    success: function (data) {  //提交视频成功
                        var taskId = data["taskId"]; //任务id
                        intervalFlag = setInterval(
                            function(){
                                referExamineRes(id, taskId);
                            }
                            ,10000);
                        swal({
                            title: "正在审核中, 请稍后.....",
                            showConfirmButton: false,
                            showCancelButton: false,
                            buttons: false
                        });
                    },
                    error: function (data) {
                        swal("Error", "网络错误，请联系管理员！", "error");
                    }
                }
            );
        } );
    }

    function referExamineRes(id ,taskId) {
        $.ajax(
            {
                type: "POST",
                url: "/videoExamine/referExamineResByTaskId",
                async: true,    //异步请求
                cache: true,
                data: {
                    "videoId": id,
                    "taskId":taskId
                },
                success: function (data) {  //提交视频成功
                    var res = data["res"];
                    if(res != "processing") {   //说明后台已经处理成功
                        window.clearInterval(intervalFlag); //停止请求
                        intervalFlag = null;
                        //1. 显示是否通过审核
                        if(res == "pass") {
                            swal("视频ID为" + id + "的视频已通过智能审核！", {
                                buttons: false,
                                timer: 1500,
                                icon: "success"
                            });
                            //2秒后刷新页面，足够显示swal()的信息
                            setTimeout(function(){window.location.reload(); },1100);
                        } else {
                            swal("视频ID为" + id + "的视频未通过智能审核！", {
                                buttons: false,
                                timer: 1500,
                                icon: "warning"
                            });
                            //2秒后刷新页面，足够显示swal()的信息
                            setTimeout(function(){window.location.reload(); },1100);
                        }
                    }
                },
                error: function (data) {
                    swal("Error", "网络错误，请联系管理员！", "error");
                }
            }
        );
    }

    function reject(id) {
        swal({
            title: "确认弹框",
            text: "确定要拒绝吗?",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((flag) => {
            if(flag) {
                $.ajax(
                    {
                        type: "POST",
                        url: "/videoExamine/accessExamine",
                        async: false,
                        cache: true,
                        data: {
                            "id": id,
                            "isPass":0
                        },
                        success: function (data) {
                            if(data["res"] == true) {
                                swal("审核已拒绝!", {
                                    buttons: false,
                                    timer: 1000
                                });
                                window.location.reload();
                            } else {
                                swal("Error", "审核通过失败", "error");
                            }
                        },
                        error: function (data) {
                            swal("Error", "网络错误，请联系管理员！", "error");
                        }
                    }
                );
            }
        } );
    }
</script>
</body>

</html>









